<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">

<title>Class: ActionController::Base</title>

<link type="text/css" media="screen" href="../rdoc.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
</script>

<script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/navigation.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search_index.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/search.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/searcher.js"></script>
<script type="text/javascript" charset="utf-8" src="../js/darkfish.js"></script>


<body id="top" class="class">
<nav id="metadata">
  <nav id="home-section" class="section">
  <h3 class="section-header">
    <a href="../index.html">Home</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </h3>
</nav>


  <nav id="search-section" class="section project-section" class="initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <h3 class="section-header">
      <input type="text" name="search" placeholder="Search" id="search-field"
             title="Type to search, Up and Down to navigate, Enter to load">
    </h3>
  </form>

  <ul id="search-results" class="initially-hidden"></ul>
</nav>


  <div id="file-metadata">
    <nav id="file-list-section" class="section">
  <h3 class="section-header">Defined In</h3>
  <ul>
    <li>lib/vbulletin_rails/core_ext.rb
  </ul>
</nav>

    
  </div>

  <div id="class-metadata">
    
    <nav id="parent-class-section" class="section">
  <h3 class="section-header">Parent</h3>
  
  <p class="link">Object
  
</nav>

    
    <!-- Method Quickref -->
<nav id="method-list-section" class="section">
  <h3 class="section-header">Methods</h3>

  <ul class="link-list">
    
    <li><a href="#method-i-act_as_vbulletin">#act_as_vbulletin</a>
    
    <li><a href="#method-i-current_vbulletin_user">#current_vbulletin_user</a>
    
    <li><a href="#method-i-set_permanent_vbulletin_session_for">#set_permanent_vbulletin_session_for</a>
    
    <li><a href="#method-i-vbulletin_login">#vbulletin_login</a>
    
    <li><a href="#method-i-vbulletin_logout">#vbulletin_logout</a>
    
  </ul>
</nav>

  </div>

  <div id="project-metadata">
    <nav id="fileindex-section" class="section project-section">
  <h3 class="section-header">Pages</h3>

  <ul>
  
    <li class="file"><a href="../LICENSE.html">LICENSE</a>
  
    <li class="file"><a href="../TODO.html">TODO</a>
  
  </ul>
</nav>

    <nav id="classindex-section" class="section project-section">
  <h3 class="section-header">Class and Module Index</h3>

  <ul class="link-list">
  
    <li><a href="../Rails/Application/Configuration.html">Rails::Application::Configuration</a>
  
    <li><a href="../VBulletinRails.html">VBulletinRails</a>
  
    <li><a href="../VBulletinRails/Session.html">VBulletinRails::Session</a>
  
    <li><a href="../VBulletinRails/User.html">VBulletinRails::User</a>
  
    <li><a href="../ActionController/Base.html">ActionController::Base</a>
  
    <li><a href="../ActiveRecord/Base.html">ActiveRecord::Base</a>
  
  </ul>
</nav>

  </div>
</nav>

<div id="documentation">
  <h1 class="class">class ActionController::Base</h1>

  <div id="description" class="description">
    
<p><a href="Base.html">ActionController::Base</a> extension for vbulletin
methods</p>

  </div><!-- description -->

  
  
  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    

    <!-- Methods -->
    
     <section id="private-instance-5Buntitled-5D-method-details" class="method-section section">
      <h3 class="section-header">Private Instance Methods</h3>

    
      <div id="method-i-act_as_vbulletin" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">act_as_vbulletin</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>It checks for VBulletin cookies and determines status of the user. When
user is logged in VBulletin, but not logged in application, this method
takes care of it and signs user in as well. Same for log out - if user
logged out from VBulletin forum, any request to application will log him
out. By default this filter is turned on. To disable it, user
skip_before_filter in desired controller or globally.</p>

<p>Example</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">ApplicationController</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ActionController</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>
  <span class="ruby-identifier">skip_before_filter</span> :<span class="ruby-identifier">act_as_vbulletin</span>
<span class="ruby-keyword">end</span>
</pre>
          

          
          <div class="method-source-code" id="act_as_vbulletin-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/core_ext.rb, line 164</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">act_as_vbulletin</span>
  <span class="ruby-keyword">if</span> (<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_sessionhash</span>] <span class="ruby-keyword">and</span> (<span class="ruby-identifier">vb_session</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span>.<span class="ruby-identifier">find_by_sessionhash</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_sessionhash</span>])) <span class="ruby-keyword">and</span> <span class="ruby-identifier">vb_session</span>.<span class="ruby-identifier">userid</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>) <span class="ruby-keyword">or</span>
    (<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_userid</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-keyword">and</span> (<span class="ruby-identifier">vb_user</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_userid</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_userid</span>])) <span class="ruby-keyword">and</span> <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">authenticate_bb_password</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_password</span>]))

    <span class="ruby-keyword">if</span> <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_userid</span>].<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-keyword">and</span> (<span class="ruby-identifier">vb_user</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_userid</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_userid</span>])) <span class="ruby-keyword">and</span> <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">authenticate_bb_password</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_password</span>])
      <span class="ruby-identifier">vb_session</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span>.<span class="ruby-identifier">set</span>(<span class="ruby-value">:request</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">request</span>, <span class="ruby-value">:user</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">vb_user</span>)
      <span class="ruby-identifier">set_permanent_vbulletin_session_for</span> <span class="ruby-identifier">vb_user</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-identifier">session</span>[<span class="ruby-value">:vbulletin_userid</span>] = <span class="ruby-identifier">vb_session</span>.<span class="ruby-identifier">userid</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">session</span>[<span class="ruby-value">:vbulletin_userid</span>]
    <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_lastactivity</span>], <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_lastvisit</span>] = <span class="ruby-identifier">vb_session</span>.<span class="ruby-identifier">update_timestamps</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">session</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:vbulletin_userid</span>)
    <span class="ruby-identifier">session</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:vbulletin_permanent</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- act_as_vbulletin-source -->
          
        </div>

        

        
      </div><!-- act_as_vbulletin-method -->

    
      <div id="method-i-current_vbulletin_user" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">current_vbulletin_user</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Returns <a href="../VBulletinRails/User.html">VBulletinRails::User</a>
object of currently logged in user. Analogic to standard, convenctional
<code>current_user</code> method.</p>
          

          
          <div class="method-source-code" id="current_vbulletin_user-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/core_ext.rb, line 200</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">current_vbulletin_user</span>
  <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_userid</span>(<span class="ruby-identifier">session</span>[<span class="ruby-value">:vbulletin_userid</span>])
<span class="ruby-keyword">end</span></pre>
          </div><!-- current_vbulletin_user-source -->
          
        </div>

        

        
      </div><!-- current_vbulletin_user-method -->

    
      <div id="method-i-set_permanent_vbulletin_session_for" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">set_permanent_vbulletin_session_for</span><span
            class="method-args">(vb_user)</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>If your application uses “Remember me” variation, this method takes care
for VBulletin and sets remember me cookie as well. It takes <a
href="../VBulletinRails/User.html">VBulletinRails::User</a> instance as
parameter. It also sets <code>session[:vbulletin_permanent]</code> to
<code>true</code> which can be checked in your application if needed.</p>

<p>To use it, a <code>config.vbulletin.cookie_salt</code> must be set. See: <a
href="../Rails/Application/Configuration.html">Rails::Application::Configuration</a>
vbulletin options</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">SessionsController</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">ApplicationController</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier">create</span>
    <span class="ruby-identifier">vb_user</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_email</span>(<span class="ruby-string">'user@example.com'</span>)
    <span class="ruby-identifier">set_permanent_vbulletin_session_for</span> <span class="ruby-identifier">vb_user</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
</pre>
          

          
          <div class="method-source-code" id="set_permanent_vbulletin_session_for-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/core_ext.rb, line 193</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">set_permanent_vbulletin_session_for</span> <span class="ruby-identifier">vb_user</span>
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">permanent</span>[<span class="ruby-value">:bb_userid</span>] = <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">userid</span>
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">permanent</span>[<span class="ruby-value">:bb_password</span>] = <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">bb_password</span>
  <span class="ruby-identifier">session</span>[<span class="ruby-value">:vbulletin_permanent</span>] = <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- set_permanent_vbulletin_session_for-source -->
          
        </div>

        

        
      </div><!-- set_permanent_vbulletin_session_for-method -->

    
      <div id="method-i-vbulletin_login" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">vbulletin_login</span><span
            class="method-args">(options = {})</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Signs in VBulletin user, when correct email/username and password are
provided It also sets <code>session[:vbulletin_userid]</code> to
<code>VBulletinRails::User#userid</code> which can be checked in your
application if needed.</p>

<pre class="ruby"><span class="ruby-identifier">vbulletin_login</span> :<span class="ruby-identifier">email</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user@example.com'</span>, :<span class="ruby-identifier">password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user password'</span> <span class="ruby-comment"># signs in by user email</span>
<span class="ruby-identifier">vbulletin_login</span> :<span class="ruby-identifier">username</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'username'</span>,      :<span class="ruby-identifier">password</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-string">'user password'</span> <span class="ruby-comment"># signs in by username</span>
</pre>
          

          
          <div class="method-source-code" id="vbulletin_login-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/core_ext.rb, line 126</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">vbulletin_login</span> <span class="ruby-identifier">options</span> = {}
  <span class="ruby-identifier">vb_user</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">vb_user</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_email</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:email</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:email</span>]
  <span class="ruby-identifier">vb_user</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">User</span>.<span class="ruby-identifier">find_by_username</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:username</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:username</span>] <span class="ruby-keyword">and</span> <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">blank?</span>

  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">vb_user</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">authenticate</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value">:password</span>])

  <span class="ruby-identifier">vb_session</span> = <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span>.<span class="ruby-identifier">set</span>(<span class="ruby-identifier">options</span>.<span class="ruby-identifier">merge</span>({<span class="ruby-value">:request</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">request</span>, <span class="ruby-value">:user</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">vb_user</span>}))
  <span class="ruby-identifier">session</span>[<span class="ruby-value">:vbulletin_userid</span>] = <span class="ruby-identifier">vb_user</span>.<span class="ruby-identifier">userid</span>
  <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_lastactivity</span>], <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_lastvisit</span>] = <span class="ruby-identifier">vb_session</span>.<span class="ruby-identifier">update_timestamps</span>
  <span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_sessionhash</span>] = <span class="ruby-identifier">vb_session</span>.<span class="ruby-identifier">sessionhash</span>

  <span class="ruby-identifier">set_permanent_vbulletin_session_for</span> <span class="ruby-identifier">vb_user</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value">:permanent</span>]

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">vb_user</span>
<span class="ruby-keyword">end</span></pre>
          </div><!-- vbulletin_login-source -->
          
        </div>

        

        
      </div><!-- vbulletin_login-method -->

    
      <div id="method-i-vbulletin_logout" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">vbulletin_logout</span><span
            class="method-args">()</span>
          <span class="method-click-advice">click to toggle source</span>
        </div>
        

        <div class="method-description">
          
          <p>Destroys VBulletin user session</p>
          

          
          <div class="method-source-code" id="vbulletin_logout-source">
            <pre><span class="ruby-comment"># File lib/vbulletin_rails/core_ext.rb, line 144</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">vbulletin_logout</span>
  <span class="ruby-constant">VBulletinRails</span><span class="ruby-operator">::</span><span class="ruby-constant">Session</span>.<span class="ruby-identifier">destroy</span>(<span class="ruby-identifier">cookies</span>[<span class="ruby-value">:bb_sessionhash</span>])
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:bb_lastactivity</span>)
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:bb_lastvisit</span>)
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:bb_sessionhash</span>)
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:bb_userid</span>)
  <span class="ruby-identifier">cookies</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:bb_password</span>)
  <span class="ruby-identifier">session</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:vbulletin_userid</span>)
  <span class="ruby-identifier">session</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-value">:vbulletin_permanent</span>)
<span class="ruby-keyword">end</span></pre>
          </div><!-- vbulletin_logout-source -->
          
        </div>

        

        
      </div><!-- vbulletin_logout-method -->

    
    </section><!-- private-instance-method-details -->
  
  </section><!-- 5Buntitled-5D -->

</div><!-- documentation -->


<footer id="validator-badges">
  <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
  <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 3.11.
  <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
</footer>

